using UnityEngine;

namespace Light
{
    public class AudioManager : SingletonMono<AudioManager>
    {
        [SerializeField] private AudioClip BGM;
        [SerializeField] private AudioSource[] sfx;

        protected override void Awake()
        {
            base.Awake();
            sfx = GetComponentsInChildren<AudioSource>();
        }

        //������Ƶ
        public void PlaySFX(AudioClip audioClip)
        {
            sfx[1].PlayOneShot(audioClip);
        }

        //���������Ƶ
        public void PlayRandomSFX(AudioClip[] audioClips)
        {
            if (audioClips.Length != 0)
                PlaySFX(audioClips[Random.Range(0, audioClips.Length)]);
        }

        public void PlayBGM()
        {
            sfx[0].clip = BGM;
            sfx[0].loop = true;
            sfx[0].Play();
        }

        public void PauseBGM()
        {
            sfx?[0].Pause();
        }

        public void setBGM(AudioClip audio)
        {
            BGM = audio;
            PauseBGM();
            PlayBGM();
        }
    }
}